home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / extras / programm / a56 / examples / sixcomb.a56 < prev    next >
Text File  |  1995-04-27  |  9KB  |  439 lines

  1. ;***************************************************************
  2. ; A stereo reverb for the DSP56001 signal processor.  Based on,
  3. ;    Moorer, James A. "About This Reverberation Business."
  4. ;    Computer Music Journal Vol 3, No. 2 (1979), pp. 13-28.
  5. ;
  6. ;   reprinted in,
  7. ;
  8. ;    Roads, Curtis, and Strawn, John, ed., _Foundations
  9. ;    of Computer Music_, pp. 605-639, MIT Press, 1985.
  10. ;    ISBN 0-262-68051-3 (paper)
  11. ;    ISBN 0-262-181142 (hard)
  12. ;
  13. ; Each comb filter uses a low-pass filter in the feedback path.
  14. ; The combs and all-pass filter delay lines use a prime-number
  15. ; of stages to improve diffusion.
  16. ;
  17. ; The output all-pass stage is replicated for left/right
  18. ; decorrelation.  Each side uses slightly different gains
  19. ; and delay lengths.  This works a lot better than just inverting
  20. ; one side and adding in the input.
  21. ;
  22. ; I left out the early-reflection FIR filter because I needed the cycles
  23. ; for other effects.
  24. ;
  25. ; Quinn Jensen (jensenq@qcj.icon.com)
  26. ;
  27. ;***************************************************************
  28.     psect    vectors        p:$0000:$0040
  29.     psect    hf_code        p:$0040:$0200
  30.     psect    hf_datax    x:$0000:$0040
  31.     psect    hf_datax1    x:$0040:$0100
  32.     psect    hf_datay    y:$0000:$0040
  33.     psect    hf_datay1    y:$0040:$0100
  34.     psect    midi_data    x:$0400:$1000
  35.     psect    lo_data        x:$1000:$F000
  36.     psect    lo_code        p:$F000:$FE00
  37.     psect    loader        p:$FE00:$FFFF
  38.     psect    iox        x:$FFC0:$FFFF
  39.     psect    ioy        y:$FFC0:$FFFF
  40. ;
  41. ; some oft-used constants
  42. ;
  43.     psect    hf_datax
  44. ffff    dc    $FFFF        ;used a lot for modulus
  45. ONE    equ    $7FFFFF        ;"one"
  46. one    dc    ONE        ;"one"
  47. ;
  48. ; L/R inputs and outputs
  49. ;
  50. in_l    dc    0.0      
  51. in_r    dc    0.0      
  52. out_l    dc    0.0      
  53. out_r    dc    0.0      
  54. ;
  55. ; recompute comb gains g1 and g2
  56. ;
  57. recalc_comb_gains
  58.     move        x:<constsp,r0
  59.     movec        x:<ffff,m0
  60.     move        x:lowpass_cutoff_start,b
  61.     move        x:lowpass_cutoff_slope,y1
  62.     move        x:comb_g,x1
  63.     move        #0.5,x0
  64.  
  65.     do    #6,recalc_loop
  66.       clr    a    (r0)+        ;skip over the modulus const
  67.       add    x0,a    b,y0
  68.       mac    x0,y0,a            ;g1 = .5 * b + .5
  69.       clr    a    a,y0        ;y0 = g1
  70.       add    x1,a    y0,y:(r0)+    ;store g1 in table
  71.       macr    -x1,y0,a        ;g2 = g(1-g1) = g - g*g1 with limiting
  72.       add    y1,b    a,y:(r0)+    ;update b, store g2 in table
  73. recalc_loop
  74.     rts
  75.  
  76.     psect    midi_data
  77. ;
  78. ; default values for midi-derived parameters
  79. ;
  80. lowpass_cutoff_start
  81.     dc    -0.3906250    ; ctl value of 39
  82. lowpass_cutoff_slope
  83.     dc    0.0468750    ; ctl value of 67
  84. comb_g
  85.     dc    0.8325507974    ; ctl value of 57
  86. ;
  87. ; preset comb-length arrays
  88. ;
  89. define(COMBLEN, `
  90. ; comb lenths $2,$3,$4,$5,$6,$7
  91. comblen_$1
  92.     dc    $2-1
  93.     dc    $3-1
  94.     dc    $4-1
  95.     dc    $5-1
  96.     dc    $6-1
  97.     dc    $7-1
  98. ')
  99.  
  100. COMBLEN(1, 383, 433, 467, 523, 557, 601)
  101. COMBLEN(2, 509, 577, 631, 701, 743, 797)
  102. COMBLEN(3, 683, 769, 839, 937, 991, 1069)
  103. COMBLEN(4, 919, 1021, 1117, 1249, 1319, 1427)
  104. COMBLEN(5, 1223, 1367, 1489, 1657, 1759, 1901)
  105. COMBLEN(6, 1627, 1823, 1987, 2213, 2341, 2539)
  106.  
  107. ;;;;;;;;;;;;;;;;;;;;;;;
  108. ; reverb filters
  109. ;;;;;;;;;;;;;;;;;;;;;;;
  110.  
  111. ;  Reverb filter lengths and coefficients     
  112. ;  6 comb reverb with prime delay lines
  113. ;  Sun Oct 24 13:53:51 1993
  114. ;  
  115. ;                          Sample rate        32.5520830 kHz      
  116. ;                          g                   0.8400000
  117. ;  
  118. ;                    status      STABLE       
  119. ;         delay      near prime lengths actual
  120. ;  stage   (ms)   len  high   low  best  delay        g1        g2
  121. ;  ---------------------------------------------------------------
  122. ;  Comb 1  50.0  1628  1637  1627  1627 49.981 0.3064583 0.5825750
  123. ;  Comb 2  56.0  1823  1823  1823  1823 56.003 0.3264583 0.5657750
  124. ;  Comb 3  61.0  1986  1987  1979  1987 61.041 0.3464583 0.5489750
  125. ;  Comb 4  68.0  2214  2221  2213  2213 67.983 0.3594792 0.5380375
  126. ;  Comb 5  72.0  2344  2347  2341  2341 71.916 0.3694792 0.5296375
  127. ;  Comb 6  78.0  2539  2539  2539  2539 77.998 0.4243750 0.4835250
  128. ;  All      6.0   195   197   193   193  5.929 0.7000000
  129.  
  130. ; COMB(name, length, modulus, g1, g2)
  131.  
  132. define(COMB, `
  133. ; storage for "$1" length=$2 modulus=$3 g1=$4 g2=$5
  134.  
  135.     psect    lo_data
  136.     align    $3
  137. $1d
  138. $1m    equ    $2-1
  139.     org    x:$1d+$1m
  140.     psect    hf_datax
  141. $1g1    equ    $4
  142. $1g2    equ    $5
  143. ')
  144.  
  145. COMB(c1, 1627, 2048, 0.3046875, 0.5812382)
  146. COMB(a1, 193, 256, 0.7000000, 0.0000000)
  147. COMB(c2, 1823, 2048, 0.3281250, 0.5616459)
  148. COMB(c3, 1987, 2048, 0.3515625, 0.5420536)
  149. COMB(c4, 2213, 4096, 0.3750000, 0.5224613)
  150. COMB(a2, 207, 256, 0.7500000, 0.0000000)
  151. COMB(c5, 2341, 4096, 0.3984375, 0.5028690)
  152. COMB(c6, 2539, 4096, 0.4218750, 0.4832767)
  153.  
  154.     psect    hf_datax
  155. a1r    dc    a1d
  156. a1md    dc    a1m
  157. a1g1d    dc    a1g1
  158. a2r    dc    a2d
  159. a2md    dc    a2m
  160. a2g1d    dc    a2g1
  161.     psect    hf_datay
  162. curaddrp
  163.     dc    curaddr
  164.     psect    hf_datax
  165. constsp    dc    consts
  166. lowstatep
  167.     dc    lowstate
  168.  
  169.     psect    hf_datax1
  170. curaddr
  171.     dc    c1d
  172.     dc    c2d
  173.     dc    c3d
  174.     dc    c4d
  175.     dc    c5d
  176.     dc    c6d
  177.  
  178.     psect    hf_datay1
  179. consts
  180.     dc    c1m
  181.     dc    c1g1
  182.     dc    c1g2
  183.     dc    c2m
  184.     dc    c2g1
  185.     dc    c2g2
  186.     dc    c3m
  187.     dc    c3g1
  188.     dc    c3g2
  189.     dc    c4m
  190.     dc    c4g1
  191.     dc    c4g2
  192.     dc    c5m
  193.     dc    c5g1
  194.     dc    c5g2
  195.     dc    c6m
  196.     dc    c6g1
  197.     dc    c6g2
  198.  
  199.     psect    hf_datax1
  200. lowstate
  201.     dc    0
  202.     dc    0
  203.     dc    0
  204.     dc    0
  205.     dc    0
  206.     dc    0
  207.  
  208. ;;;;;;;;;;;;;;;;;;;;;;;
  209. ; miscellaneous signals
  210. ;;;;;;;;;;;;;;;;;;;;;;;
  211.  
  212.     psect    hf_datax
  213. L_overall
  214.     dc    $7FFFFF
  215. R_overall
  216.     dc    $7FFFFF
  217.  
  218. ;;;;;;;;;;;;;;;;;;;;;;;
  219. ; signal vector
  220. ;;;;;;;;;;;;;;;;;;;;;;;
  221.     psect    hf_datax
  222.     align 8
  223. signal_vector
  224. Lin    dc    0.0
  225. Rin    dc    0.0
  226. Reverb_L
  227.     dc    0.0
  228. Reverb_R    
  229.     dc    0.0
  230.  
  231. Lout
  232.     dc    0
  233. Rout
  234.     dc    0
  235.  
  236.     psect hf_datay
  237. signal_vectorp
  238.     dc    signal_vector
  239. signal_mod
  240.     dc    4-1
  241.  
  242. gain_vectorsp
  243.     dc    gain_vectors
  244. ;;;;;;;;;;;;;;;;;;;;;;;
  245. ; gain matrix
  246. ;;;;;;;;;;;;;;;;;;;;;;;
  247.     psect    hf_datay1
  248. gain_vectors
  249. Reverb_gain_vector
  250. Reverb_Lin    dc 0.5
  251. Reverb_Rin    dc 0.5
  252. Reverb_Reverb_L    dc 0.0
  253. Reverb_Reverb_R    dc 0.0
  254.  
  255. Lout_gain_vector
  256. Lout_Lin    dc 0.0
  257. Lout_Rin    dc 0.0
  258. Lout_Reverb_L    dc ONE
  259. Lout_Reverb_R    dc 0.0
  260.  
  261. Rout_gain_vector
  262. Rout_Lin    dc 0.0
  263. Rout_Rin    dc 0.0
  264. Rout_Reverb_L    dc 0.0
  265. Rout_Reverb_R    dc -1.0
  266.  
  267. ;***************************************************************
  268. ;
  269. ;    init code - call hf_init at first and any time when
  270. ;    parameters change
  271. ;
  272. ;***************************************************************
  273.     psect    lo_code
  274.  
  275. hf_init
  276. ;
  277. ;    clear out the filter delay lines
  278. ;
  279. define(CLEAR_LINE, `
  280.     move        #$1d,r0
  281.     movec        #$1m,m0
  282.     jsr    clear_line_r0
  283. ')
  284.  
  285. CLEAR_LINE(c1)
  286. CLEAR_LINE(c2)
  287. CLEAR_LINE(c3)
  288. CLEAR_LINE(c4)
  289. CLEAR_LINE(c5)
  290. CLEAR_LINE(c6)
  291. CLEAR_LINE(a1)
  292. CLEAR_LINE(a2)
  293.     jsr    recalc_comb_gains
  294.     rts
  295.  
  296. clear_line_r0
  297.     clr    a
  298.     rep    #0
  299.       move        a,x:(r0)+
  300.     rts
  301.  
  302. ;***************************************************************
  303. ;
  304. ;    sample rate computations
  305. ;
  306. ;    Call hf_comp once per sample.
  307. ;    Globals in_l and in_r should have the left and right
  308. ;    input samples.  When hf_comp returns, out_l and out_r
  309. ;    will be ready.
  310. ;
  311. ;***************************************************************
  312.  
  313. ;
  314. ; fs = 32.552083 kHz
  315. ;
  316.     psect    hf_code
  317.  
  318. hf_comp
  319. ;
  320. ;    copy inputs
  321. ;
  322.     move        x:<in_l,a
  323.     move        a,x:<Lin
  324.     move        x:<in_r,a
  325.     move        a,x:<Rin
  326. ;
  327. ;    compute outputs using matrix multiply
  328. ;
  329. ; [reverb_in out_l out_r] = [gain_vector] * [signal_vector]
  330. ;
  331.     move        y:<signal_vectorp,r0
  332.     movec        y:<signal_mod,m0
  333.     move        y:<gain_vectorsp,r4
  334.     movec        x:<ffff,m4
  335.     move        x:<L_overall,y1        ;and wait for m4
  336.     clr    a    x:(r0)+,x0 y:(r4)+,y0
  337.     mac    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  338.     mac    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  339.     mac    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  340.     macr    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  341.     clr    a    a,b            ;b is reverb_in
  342.     mac    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  343.     mac    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  344.     mac    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  345.     macr    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  346.     clr    a    a,x1
  347.     mpy    x1,y1,a    x:<R_overall,y1
  348.     clr    a    a,x:<out_l
  349.     mac    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  350.     mac    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  351.     mac    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  352.     macr    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  353.     clr    a    a,x1
  354.     mpy    x1,y1,a
  355.     clr    a    a,x:<out_r
  356. ;
  357. ; r1    lowstate vector
  358. ; m1    -1
  359. ; r4    ptr to modulus,g1,g2 constants
  360. ; m4    -1
  361. ; r5    curaddr ptr
  362. ; m5    -1
  363. ; b    comb out accum
  364. ; x0    scaled comb in
  365. ;
  366. ;
  367. ;    set up reverb input
  368. ;
  369.     clr    b    b,x0            ;get reverb_in
  370.     move        #1.0/16,x1        ;allow 4 bits of headroom
  371.     mpyr    x0,x1,a                ;and 4 bits of noise
  372.     move        a,x0
  373.     move        x:<lowstatep,r1
  374.     movec        x:<ffff,m1
  375.     move        x:<constsp,r4
  376.     movec        m1,m4
  377.     move            y:<curaddrp,r5
  378.     movec        m1,m5
  379. ;
  380. ;    do the six combs
  381. ;
  382.     do    #6,comb_loop
  383.       move        x:(r5),r0        ;r0=curaddr
  384.       movec        y:(r4)+,m0        ;m0=modulus
  385.       move        x:(r1),x1 y:(r4)+,y1    ;x1=lowstate, y1=g1, wait for m0
  386.       move        x:(r0)+,y0        ;y0=delay out
  387.       add    y0,b        y0,a        ;a=delay out
  388.       macr    x1,y1,a        y:(r4)+,y1    ;a=out+g1*lowstate, y1=g2
  389.       clr    a          a,x:(r1)+ a,y0        ;y0=new lowstate
  390.       add    x0,a    r0,x:(r5)+        ;a=in, save ptr
  391.       macr    y0,y1,a                ;a=in+g2*g1*lowstate
  392.       move        a,x:-(r0)        ;store delay in (takes 2 cyc)
  393. comb_loop
  394. ;
  395. ;    scale
  396. ;
  397.     rnd    b    #$15,x0        ;scale by ~1/6
  398.     move        b,y0
  399.     mpyr    x0,y0,b
  400.     move        b,y1        ;save b for right chan
  401. ;
  402. ;    allpass L
  403. ;
  404.     move        x:<a1r,r0
  405.     movec        x:<a1md,m0
  406.     move        x:<a1g1d,x0
  407.     move        x:(r0),x1
  408.     macr    x0,x1,b    x1,a
  409.     move            b,y0
  410.     macr    -x0,y0,a b,x:(r0)+
  411.     asl    a          r0,x:<a1r
  412.     asl    a            ;get rid of the headroom
  413.     asl    a
  414.     asl    a
  415.     move        a,x:<Reverb_L
  416. ;
  417. ;    allpass R
  418. ;
  419.     tfr    y1,b    x:<a2r,r0
  420.     movec        x:<a2md,m0
  421.     neg    b    x:<a2g1d,x0
  422.     move        x:(r0),x1
  423.     macr    x0,x1,b    x1,a
  424.     move            b,y0
  425.     macr    -x0,y0,a b,x:(r0)+
  426.     asl    a    r0,x:<a2r
  427.     asl    a
  428.     asl    a
  429.     asl    a
  430.     move        a,x:<Reverb_R
  431. ;
  432. ;    done
  433. ;
  434.     rts
  435.  
  436.     end
  437.